layui.use(['table', 'form', 'jquery', 'common'], function() {
	let table = layui.table;
	let form = layui.form;
	let $ = layui.jquery;
	let common  = layui.common;
	let cols = [
		[
			{
				title: '插件名称',
				field: 'name',
				align: 'center',
				width: 100
			},
			{
				title: '插件介绍',
				field: 'readme',
				align: 'center'
			},
			{
				title: '更新时间',
				field: 'addtime',
				align: 'center',
			},
			{
				title: '插件下载',
				field: 'notify_url',
				align: 'center',
				templet:function(d){
				    return `<button lay-event="down" class="layui-btn layui-btn-success layui-btn-sm">立即下载</button>
`
				}
			}
		]
	]

	table.render({
		elem: '#Plugin_table',
		url: './ajax/PlugingetDataList',
		page: true,
		cols: cols,
		cellMinWidth: 170,
		skin: 'line',
		toolbar: '#user-toolbar',
		defaultToolbar: [{
			title: '刷新',
			layEvent: 'refresh',
			icon: 'layui-icon-refresh',
		}, 'filter', 'print', 'exports']
	});

	table.on('tool(Plugin_table)', function(obj) {
		if (obj.event === 'down') {
			window.down(obj.data['url']);
		}
	});

	table.on('toolbar(Plugin_table)', function(obj) {
		if (obj.event === 'refresh') {
			window.refresh();
		} 
	});

	form.on('submit(user-query)', function(data) {
		table.reload('Plugin_table', {
			where: data.field,
			page: {
				curr: 1
			}
		})
		return false;
	});


	window.down = function(url) {
	  
      window.open(url, '_blank');
    }
	

	window.refresh = function(param) {
		table.reload('Plugin_table');
	}
})